package com.ruoyi.web.controller.dgw;

import java.util.List;
import java.util.Map;

import io.swagger.annotations.ApiModelProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.Vaccine;
import com.ruoyi.dgw.service.IVaccineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 疫苗Controller
 * 
 * @author lw
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/dgw/vaccine")
public class VaccineController extends BaseController
{
    @Autowired
    private IVaccineService vaccineService;

    /**
     * 查询疫苗列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:vaccine:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vaccine vaccine)
    {
        startPage();
        List<Vaccine> list = vaccineService.selectVaccineList(vaccine);
        return getDataTable(list);
    }

    /**
     * 导出疫苗列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:vaccine:export')")
    @Log(title = "疫苗", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Vaccine vaccine)
    {

        List<Vaccine> list = vaccineService.selectVaccineList(vaccine);
        ExcelUtil<Vaccine> util = new ExcelUtil<Vaccine>(Vaccine.class);
        return util.exportExcel(list, "疫苗数据");
    }

    /**
     * 获取疫苗详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:vaccine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(vaccineService.selectVaccineById(id));
    }

    /**
     * 新增疫苗
     */
    @PreAuthorize("@ss.hasPermi('dgw:vaccine:add')")
    @Log(title = "疫苗", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vaccine vaccine)
    {
        return toAjax(vaccineService.insertVaccine(vaccine));
    }

    /**
     * 修改疫苗
     */
    @PreAuthorize("@ss.hasPermi('dgw:vaccine:edit')")
    @Log(title = "疫苗", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vaccine vaccine)
    {
        return toAjax(vaccineService.updateVaccine(vaccine));
    }

    /**
     * 删除疫苗
     */
    @PreAuthorize("@ss.hasPermi('dgw:vaccine:remove')")
    @Log(title = "疫苗", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vaccineService.deleteVaccineByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('dgw:vaccine:list')")
    @GetMapping("/listSum")
    @ApiModelProperty(name = "查询免疫总量")
    public TableDataInfo querySum(String nickName){
       List<Map<String,String>> map = vaccineService.querySum(nickName);
        return getDataTable(map);
    }
}
